import 'package:extended_tabs/extended_tabs.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:laos_mall/common/style/app_style.dart';
import 'package:laos_mall/common/style/extension_util.dart';
import 'package:laos_mall/common/widght/custom_tab_indicator.dart';
import 'package:laos_mall/common/widght/webView_widget.dart';
import 'package:laos_mall/pages/main/home/fade_image_item.dart';
import 'package:lazy_load_indexed_stack/lazy_load_indexed_stack.dart';

import 'logic.dart';

class HomePage extends StatelessWidget {
  HomePage({Key? key}) : super(key: key);

  final logic = Get.find<HomeLogic>();

  @override
  Widget build(BuildContext context) {
    // FlipListView()

    return GetBuilder<HomeLogic>(builder: (logic) {
      if (logic.categorys.isEmpty) {
        return Container(color: AppColor.primaryColor,); // 显示加载状态
      }
      else {
        return Stack(
      children: [
        // TabBarView(
        //    controller: logic.tabCtl,
        //    children: logic.categorys
        //        .map((e) => FlipListView().addContainer(color: Colors.black,radius: 0))
        //        .toList(),
        //  ),
        ExtendedTabBarView(
            shouldIgnorePointerWhenScrolling: false,
            controller: logic.tabCtl,
            children: logic.categorys.map((e) =>
                FlipListView(images: logic.getProductInCategory(e),).addContainer(color: Colors.black, radius: 0))
                .toList()
        ),
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            SizedBox(
              height: ScreenUtil().statusBarHeight,
            ),
            _buildHeader(),
            TabBar(
                isScrollable: true,
                indicatorSize: TabBarIndicatorSize.label,
                indicatorPadding: const EdgeInsets.only(
                    bottom: 10, left: 15, right: 15),
                padding: EdgeInsets.zero,
                labelColor: "#111111".toColor,
                indicator: const CustomTabIndicator(),
                // labelPadding: EdgeInsets.zero,
                controller: logic.tabCtl,
                tabs: logic.categorys
                    .map((e) =>
                    Tab(
                      text: e,

                    ).addContainer(width: 60, color: Colors.transparent))
                    .toList()),
          ],
        ),
      ],
      );
      }
    });
  }

  Widget _buildHeader() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Text(
          "APP-NAME".tr,
          style: TextStyle(fontSize: 35.sp, fontStyle: FontStyle.italic),
        ),
        Image.asset(
          'ic_language'.toImgPath(),
          width: 18.w,
          height: 18.w,
        ).addGestureTap(logic.jumpLanguage)
      ],
    )
        .addContainer(height: 74.w, color: Colors.transparent)
        .addPadding(EdgeInsets.only(left: 20.w, right: 32.w));
  }
}
